$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        um: null,
        form: null,
        init: function () {
            this.form = $('#table');
            this.funObj().newEditor('', true);
            this.listener();
        },
        listener: function () {
            var $this = this;
            //审核
            $this.form.on('click','[id^="check_"]',function () {
                var id = $(this).attr("id").split("check_")[1];
                $this.funObj().checkNote(id);
            });
            //提交审核信息
            $this.form.on('click','[id^="submit_"]',function () {
                var id = $(this).attr("id").split("submit_")[1];
                $this.funObj().addCheckData(id);
            });
        },
        funObj: function () {
            var $this = this;
            return {
                checkNote: function (_id) {
                    $this.form.find('[id=editContent_'+_id+']').slideToggle('slow');
                },
                addCheckData: function (_id) {
                    var sContent = $this.funObj().newEditor(_id).getContent();
                    xhExtra.ajaxRequest('Device/addRegisterCheck', {device: devName, tabletId: tabletId, noteId: _id, sContent: sContent}, {}, function (data) {
                        if (xhExtra.checkError(data)) {
                            return false;
                        } else {
                            window.top.xhTop.showSuccess(data.msg);
                            location.reload();
                            window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        }
                    });
                },
                newEditor: function (id, all) {
                    if (!id && all) {
                        $this.form.find('[id^="sContent_'+'"]').each(function () {
                            var id = $(this).attr("id").split("sContent_")[1];
                            UE.getEditor('sContent_'+id, {
                                autoHeightEnabled: true,
                                textarea: 'sContent_'+id,
                                initialFrameWidth: '100%',
                                imageScaleEnabled: false,
                                toolbars: []
                            });
                        });
                    } else {
                        if (id) {
                            return UE.getEditor('sContent_'+id, {
                                autoHeightEnabled: true,
                                textarea: 'sContent_'+id,
                                initialFrameWidth: '100%',
                                imageScaleEnabled: false,
                                toolbars: []
                            });
                        }
                    }
                }
            }
        }
    }
};

